package com.example.mybatisplus.web.controller;

import com.example.mybatisplus.model.domain.VisitInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.ConsultInfoService;
import com.example.mybatisplus.model.domain.ConsultInfo;

import java.util.List;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2023-10-16
 * @version v1.0
 */
@Controller
@RequestMapping("/api/consultInfo")
public class ConsultInfoController {

    private final Logger logger = LoggerFactory.getLogger( ConsultInfoController.class );

    @Autowired
    private ConsultInfoService consultInfoService;

    @RequestMapping(value = "/getAllById/{consultId}", method = RequestMethod.GET)
    @ResponseBody
    public JsonResponse getAllById(@PathVariable("consultId") Long consultId)throws Exception {
        ConsultInfo consultInfo =  consultInfoService.getAllById(consultId);
        return JsonResponse.success(consultInfo);
    }
    /*全部查询*/
    @RequestMapping("getTotal")
    @ResponseBody
    public JsonResponse getTotal(@RequestBody ConsultInfo consultInfo){
        List<ConsultInfo> consultInfos=consultInfoService.getTotal(consultInfo);
        return JsonResponse.success(consultInfos);
    }
    /*一次查出相应页数的数据并且可以模糊查询*/
    @RequestMapping(value="/getAll/{page}/{limit}")
    @ResponseBody
    public JsonResponse getAll(@PathVariable("page") Long page,@PathVariable("limit") Long limit,@RequestBody ConsultInfo consultInfo){
        List<ConsultInfo> consultInfos=consultInfoService.getAll(page,limit,consultInfo);
        return JsonResponse.success(consultInfos);
    }
    /*根据初访编号进行假删除多个删除*/
    @RequestMapping(value="/deleteByConsultIds")
    @ResponseBody
    public JsonResponse deleteByConsultIds(@RequestBody List<Long> consultIds) {
        consultInfoService.deleteByConsultIds(consultIds);
        return JsonResponse.success(null);
    }
    //审核
    @RequestMapping(value="/pass/{consultId}/{type}/{status}")
    @ResponseBody
    public JsonResponse passByVisitId(@PathVariable("consultId") Long consultId,@PathVariable("type") Long type,@PathVariable("status") Long status){
        consultInfoService.passByConsultId(consultId,type,status);
        return JsonResponse.success(null);
    }
    //修改咨询信息
    @RequestMapping(value="/modifyConsult")
    @ResponseBody
    public JsonResponse modifyConsult(@RequestBody ConsultInfo consultInfo){
        consultInfoService.modifyConsult(consultInfo);
        return JsonResponse.success(null);
    }
    //初访员更新咨询结论和详情
    @RequestMapping(value="/submitResult")
    @ResponseBody
    public JsonResponse modifyResult(@RequestBody ConsultInfo consultInfo){
        consultInfoService.modifyResult(consultInfo);
        return JsonResponse.success(null);
    }
    //新增咨询信息
    @RequestMapping(value="/addConsult")
    @ResponseBody
    public JsonResponse addConsult(@RequestBody ConsultInfo consultInfo){
        consultInfoService.addConsult(consultInfo);
        return JsonResponse.success(null);
    }
    //获取咨询信息所属的初访信息全部
    @RequestMapping(value="/GetConsultByVisits")
    @ResponseBody
    public JsonResponse getCounsultByVisits(String visitId){
        List<ConsultInfo> consultInfos=consultInfoService.getConsultByVisits(visitId);
        return JsonResponse.success(consultInfos);
    }
}

